package edu.hgnc.test;


import edu.hgnc.methodOverrides.lookup.FruitPlate;
import edu.hgnc.methodOverrides.replace.OriginalDog;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 测试lookup-method,repalce-method
 *
 * spring中默认的对象都是单例的，spring会在一级缓存中持有该对象，方便下次直接获取
 * 那么如果是原型作用域的话，会创建一个新的对象
 * 如果想在一个单例模式的bean下引用一个原型模式的bean，怎么办
 * 在此时就需要引用lookup-method标签来解决此问题
 *
 */
public class JustTest2 {

	@Test
	public void test01(){
		System.out.println("======================================================");
		System.out.println("hello,when you see me,that's mean you are test succeed~");
		System.out.println("======================================================");
	}

	@Test
	public void test02() {
		ApplicationContext context = new ClassPathXmlApplicationContext("methodOverrides.xml");
		FruitPlate plate = (FruitPlate) context.getBean("fruit-plate1");
		plate.getFruit();
		// 引用的是原型对象，每次都创建类新的对象
		System.out.println(plate.getFruit().toString());
		System.out.println(plate.getFruit().toString());

		FruitPlate plate2 = (FruitPlate) context.getBean("fruit-plate2");
		plate2.getFruit();
		System.out.println(plate2.getFruit().toString());
		System.out.println(plate2.getFruit().toString());

	}
	@Test
	public void test03() {
		ApplicationContext context = new ClassPathXmlApplicationContext("methodOverrides.xml");
		OriginalDog plate = (OriginalDog) context.getBean("husky");
		// 引用的是原型对象，每次都创建类新的对象
		plate.sayHello();
		plate.sayHello("--大金--");

	}
}
